import os
import sys
from core.result_base import ResultBase
from common.logger import logger
from common.content_type import ContentType
from common.user_agent import useragent
from common.time_bdp import time_bdp
from api.register import register
import urllib3
urllib3.disable_warnings()

BASE_PATH = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(BASE_PATH)


def register_pic(access_token,session_id=time_bdp.time_stamp_13(),_t=time_bdp.time_stamp_13()):
    """
    生成图片验证码
    :param _t:
    :param session_id:必填项
    :return: 自定义的关键字返回结果 result
    """
    result = ResultBase()
    payload = {
        "_t": _t,
        "session_id": session_id
    }

    headers = {
        "Content-Type": ContentType.MULTIPART_FORM_DATA.value,
        "User-Agent": useragent.get_user_agent_one()
    }

    cookies = {
        "access_token": access_token
    }

    res = register.pic(params=payload, headers=headers,cookies=cookies)
    return res
    # result.success = False
    # if res.json()["status"] == "0":
    #     result.success = True
    # else:
    #     result.error = "接口返回码是 【 {} 】, 返回信息：{} ".format(res.json()["errstr"], res.json())
    # result.payload = res.json()
    # result.response = res
    # logger.info("生成图片验证码 ==>> 返回结果 ==>> {}".format(result.response.text))
    # return result









